<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>社萌登录</title>
		<link rel="stylesheet" type="text/css" href="../css/style.css"/>
		<script src="./layui/layui.js" charset="utf-8"></script>
		<style type="text/css">
			body{
				width: 100%;
				height: auto;
				background: url(../img/bg.jpg) no-repeat;
				background-size: cover;
			}
			html{
				height: 100%;
			}
		</style>
	</head>
	<body>
	<div class="container">
		<section id="content">
			<form action="">
				<h1>用户登录</h1>
				
				<div>
					<input type="text" placeholder="账号" required="" id="username" />
				</div>
				<div>
					<input type="password" placeholder="密码" required="" id="password" />
				</div>
				 <div class="">
					<span class="help-block u-errormessage" id="js-server-helpinfo">&nbsp;</span>			
				</div> 
				<div>
					<!-- <input type="submit" value="Log in" /> -->
					<input type="button" value="登录" class="btn btn-primary" id="js-btn-login"/>
					<input type="button" value="注册" class="btn btn-primary" id="js-btn-login1"  onClick="location.href='login-register.html'"/>
					<a href="#">忘记密码?</a>
					<!-- <a href="#">Register</a> -->
				</div>
			</form><!-- form -->
		</section><!-- content -->
	</div>
	</body>
	<script type="text/javascript">
    layui.use(['form', 'jquery'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        $('#js-btn-login').click(function(){
            $.ajax({
            	type:"POST",
            	url:"/user/login",
            	data:{
            		username:$('#username').val(),
            		password:$('#password').val()
            	},
            	dataType:"text",
            	error:function(XMLHttpRequest, textStatus, errorThrown){
            		console.log( textStatus+"     "+XMLHttpRequest+"    "+errorThrown);
            		alert("error!");
            	},
            	success:function(data){
            		console.log(data);
            		if(data == 'Stu'){
            			location.href = "/Stumain.html"
            		}else if(data == 'Man'){
            			location.href = "/Manmain.html"
            		}else{
            			alert(data);
            		}
            	}
            })
        });
    })
	</script>
</html>
